<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$Title$</title>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var pageIndex=1;
            function initNews() {
                $.ajax({
                    "url":"${pageContext.request.contextPath}/client/getPageProduct.html",
                    "type":"GET",
                    "data":"pageIndex="+pageIndex,
                    "dataType":"json",
                    "success":function (data) {
                        pageIndex=data.pageIndex;
                        $("#myTbody").html("");
                        if(data.counts!=0){
                            $(data.lists).each(function () {
                                $("#myTbody").append("<tr>" +
                                    "      <td>" + this.product.product_name + "</td>" +
                                    "      <td>" + this.product.product_price + "</td>" +
                                    "      <td>" + this.order_creation + "</td>" +
                                    "      <td>" + this.order_updatetime + "</td>" +
                                    "      <td>" + this.status.valueName + "</td>" +
                                    "      <td>" +
                                    "<a href='javascript:void(0)' class='del' id='"+this.id+"' state='"+this.order_state+"'>删除</a> &nbsp; &nbsp;" +
                                    "<a href='${pageContext.request.contextPath}/client/goSelOne.html?id="+this.id+"'>修改</a>" +
                                    "</td>" +
                                    "    </tr>")
                            })
                            $("#myTbody").append("<tr>" +
                                "<td colspan='7'>["+data.pageIndex+"/"+data.pageCount+"]</td>" +
                                "</tr>" +
                                "<tr>" +
                                "<td colspan='7'>" +
                                "<a href='javascript:void(0)' id='sy'>首页</a>" +
                                "<a href='javascript:void(0)' id='syy'>上一页</a>" +
                                "<a href='javascript:void(0)' id='xyy'>下一页</a>" +
                                "<a href='javascript:void(0)' id='my'>末页</a>" +
                                "</td>" +
                                "</tr>" );
                            $("#sy").click(function () {
                                pageIndex=1;
                                initNews();
                            });
                            $("#syy").click(function () {
                                pageIndex--;
                                initNews();
                            });

                            $("#xyy").click(function () {
                                pageIndex++;
                                initNews();
                            });

                            $("#my").click(function () {
                                pageIndex=data.pageCount;
                                initNews();
                            })

                            $(".del").click(function () {
                                delNews($(this).attr("id"),$(this).attr("state"));

                            })

                        }else{
                            $("#myTbody").html("<tr><td colspan='6' align='center'><h3>暂无数据</h3></td></tr>")
                        }

                    }
                });

            }
            function delNews(id,state) {
                $.ajax({
                    "url":"${pageContext.request.contextPath}/client/delOrder.html",
                    "type":"GET",
                    "data":{"id":id,"state":state},
                    "dataType":"text",
                    "success":function (data) {
                        if(data!=0){
                            alert("删除成功");
                            initNews();
                        }else{
                            alert("删除失败(账单还没完成)");
                            initNews();
                        }

                    }
                });

            }
            initNews();
        })
    </script>
</head>
<body>
<table  class="table table-condensed" width="700px" align="center" border="1" cellpadding="0" cellspacing="0">
    <tr align="right">
        <td>你好:${Client.customer_name}
            <a href="${pageContext.request.contextPath}/client/over.html">退出</a>
        </td>
        <td colspan="10">
            <a href="${pageContext.request.contextPath}/client/goAdd.html">添加</a>
        </td>
    </tr>
    <tr align="center">
        <td colspan="10">
            <h1>用户</h1>
        </td>
    </tr>
    <tr>
        <td>商品名称</td>
        <td>商品价格</td>
        <td>创建时间</td>
        <td>修改时间</td>
        <td>完成状态</td>
        <td>操作</td>
    </tr>
    <tbody id="myTbody"  class="table table-condensed">

    </tbody>
</table>
</body>
</html>
